<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"      
      >
    <h:head>             <meta http-equiv="expires" content="0"></meta>             <meta http-equiv="Cache-Control" content="no-cache"></meta>             <meta http-equiv="Cache-Control" content="no-cache"></meta>
        <title>.:DMES:. - Roles y Grupos</title>
        <script type="text/javascript">
            window.setTimeout("roleInit()",500);
        </script>
    </h:head>
    <h:body>
        <p:ajaxStatus onstart="PF('statusDialog').show()" oncomplete="PF('statusDialog').hide()"/>
            <p:dialog modal="true" widgetVar="statusDialog" header="Cargando..."
                      draggable="false" closable="false" resizable="false">
                <p:graphicImage value="/images/loadBar.gif"/>
            </p:dialog>
        <div>
<!--         Dialogo para guardar nuevos roles         -->
        <p:dialog id="dialogRolesSave" widgetVar="dialogRolesSave" position="center top" width="450"
                      closable="true" draggable="true" dynamic="true" header="Crear Grupos y Roles"
                      hideEffect="explode" modal="true" showEffect="explode" resizable="true">
                <h:form id="formSaveScRole">
                    <table width="98%" cellspacing="30">
                        <tr>
                            <td width="20%" align="right">
                                <p:outputLabel  for="tfNameRol" value="Nombre del Grupo:"/>
                            </td>
                            <td width="80%" align="left">
                                <p:inputText    id="tfNameRol"  value="#{scrolesBean.scRolesAdd.name}"/>
                            </td>
                        </tr>
                        <tr>
                            <td width="20%" align="right">
                                <p:outputLabel  for="tfDescriptionRol" value="Descripción:"/>
                            </td>
                            <td width="80%" align="left">
                                <p:inputTextarea    id="tfDescriptionRol"  
                                                    value="#{scrolesBean.scRolesAdd.description}" />                                    
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p:dataTable id="dataTablePermissions" value="#{scrolesBean.listAllPermissions}"
                                             paginator="true" rows="10"  var="permissions"
                                             pageLinks="40"
                                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} 
                                             {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                             rowKey="#{permissions.idModulePermission}"
                                             resizableColumns="true" 
                                             liveResize="true" rowsPerPageTemplate="10,20,30" 
                                             paginatorPosition="top" selection="#{scrolesBean.listPermissionsAdd}">

                                    <p:column  selectionMode="multiple" width="16"/>
                                    <p:column  headerText="Permiso" >
                                        <p:outputLabel value="Gestionar #{permissions.name}"/>
                                    </p:column> 
                                </p:dataTable>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <p:commandButton value="Guardar" actionListener="#{scrolesBean.saveRole()}"  
                                                 onsuccess="PF('dialogRolesSave').hide()"
                                                 update="@this,tfNameRol,tfDescriptionRol,dataTablePermissions,:formRoles:scrolesDataTable"/>
                                <p:spacer width="20"/>

                                <p:commandButton value="Cancelar" actionListener="#{scrolesBean.cleanFieldsSave()}" 
                                                 oncomplete="PF('dialogRolesSave').hide()"
                                                 update="@this,tfNameRol,tfDescriptionRol,dataTablePermissions"/>
                            </td>
                        </tr>
                    </table> 
                </h:form>
            </p:dialog> 
<!--         finaliza el dialogo para guardar roles               -->

<!--         Inicia el dialogo para actualizar roles              -->
            <p:dialog id="dialogRolesUpdate" widgetVar="dialogRolesUpdate" position="center top" width="450"
                      closable="true" draggable="true" dynamic="true" header="Actualizar Grupos y Roles"
                      hideEffect="explode" modal="true" showEffect="explode" resizable="true">
                <h:form id="formUpdateScRole">
                    <table cellspacing="30">
                        <tr> 
                            <td width="20%" align="right">
                                <p:outputLabel  for="tfNameRolUpdate" value="Nombre del Grupo:"/>
                            </td>
                            <td width="80%" align="left">
                                <p:inputText    id="tfNameRolUpdate"  value="#{scrolesBean.scRolesSelected.name}" disabled="true"/>
                            </td>
                        </tr>
                        <tr>
                            <td width="20%" align="right">
                                <p:outputLabel  for="tfDescriptionRolUpdate" value="Descripción:"/>
                            </td>
                            <td width="80%" align="left">
                                <p:inputTextarea    id="tfDescriptionRolUpdate"  
                                                    value="#{scrolesBean.scRolesSelected.description}" />                                    
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <p:dataTable id="dataTablePermissionsUpdate" value="#{scrolesBean.listAllPermissions}"
                                             paginator="true" rows="10"  var="permissions"
                                             pageLinks="40"
                                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} 
                                             {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                             rowKey="#{permissions.idModulePermission}"
                                             resizableColumns="true" 
                                             liveResize="true" rowsPerPageTemplate="10,20,30" 
                                             paginatorPosition="top" selection="#{scrolesBean.listPermissionsUpdate}">

                                    <p:column  selectionMode="multiple" width="16"/>
                                    <p:column  headerText="Permiso" >
                                        <p:outputLabel value="Gestionar #{permissions.name}"/>
                                    </p:column> 
                                </p:dataTable>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <p:commandButton value="Guardar" actionListener="#{scrolesBean.updateRole()}"  
                                                 onsuccess="PF('dialogRolesUpdate').hide()" 
                                                 update="@this,:formRoles:scrolesDataTable,tfNameRolUpdate,tfDescriptionRolUpdate"/>
                                <p:spacer width="20"/>

                                <p:commandButton value="Cancelar" 
                                                 oncomplete="PF('dialogRolesUpdate').hide()"/>
                            </td>
                        </tr>
                    </table>
                </h:form>
            </p:dialog>
<!--         finaliza el dialogo para actualizar dialogos          -->

<!--             inicia el dialogo para elimianr registros           -->
            <p:dialog id="dialogRolesDelete" widgetVar="dialogRolesDelete" 
                      closable="true" draggable="true" dynamic="true" header="Eliminar Grupos y Roles"
                      hideEffect="explode" modal="true" showEffect="explode" resizable="false" position="center top" >
                <h:form id="formDeleteScRole">
                    <table width="100%" cellspacing="30" style="padding: 0px; margin: 0px;">
                        <tr>
                            <td>
                                <p:outputLabel value="¿Desea eliminar el grupo #{scrolesBean.scRolesSelected.name}?" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <p:commandButton value="Eliminar" actionListener="#{scrolesBean.deleteRole()}"  
                                                 onsuccess="PF('dialogRolesDelete').hide()"
                                                 update="@this,:formRoles:scrolesDataTable"/>
                                <p:spacer width="20"/>

                                <p:commandButton value="Cancelar" oncomplete="PF('dialogRolesDelete').hide()"
                                                 update="@this"/>
                            </td>
                        </tr>
                    </table>
                </h:form>
            </p:dialog>
<!--            finaliza el dialogo para eliminar registros            -->

<!--           inicial el dialogo para visualizar un rol           -->
            <p:dialog id="dialogRolesView" widgetVar="dialogRolesView" position="center top" 
                                  closable="true" draggable="true" dynamic="true" header="Detalle de Grupos y Roles"
                                  hideEffect="explode" modal="true" showEffect="explode" resizable="true"
                                  >
                <h:form id="formViewScRole">
                    <table cellspacing="30">
                        <tr>
                            <td width="10%" align="right">
                                <p:outputLabel  value="Nombre del Grupo:"/>
                            </td>
                            <td width="40%" align="left">
                                <p:inputText value="#{scrolesBean.scRolesSelected.name}" disabled="true"/>
                            </td>
                            <td width="10%" align="right">
                                <p:outputLabel  value="Fecha de Creación:"/>
                            </td>
                            <td width="40%" align="left">
                                <p:inputText value="#{scrolesBean.scRolesSelected.creationDate}" disabled="true"/>
                            </td>
                        </tr>
                        <tr>
                            <td width="10%" align="right">
                                <p:outputLabel  value="Descripción:"/>
                            </td>
                            <td width="40%" align="left">
                                <p:inputText id="tfDescriptionView" value="#{scrolesBean.scRolesSelected.description}"
                                             disabled="true" title="#{scrolesBean.scRolesSelected.description}"/>
                            </td>
                            <td width="10%" align="right">
                                <p:outputLabel  value="Fecha de Modificación:"/>
                            </td>
                            <td width="40%" align="left">
                                <p:inputText value="#{scrolesBean.scRolesSelected.modifyDate}" disabled="true"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" align="center">
                                <p:dataTable id="dataTablePermissionsUpdate" value="#{scrolesBean.listAllPermissions}"
                                    style="width: 400px;"
                                    paginator="true" rows="10"  var="permissions"
                                    pageLinks="40"
                                    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} 
                                    {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                    rowKey="#{permissions.idModulePermission}"
                                    resizableColumns="true" selection="#{scrolesBean.listPermissionsUpdate}"
                                    disabledSelection="true"
                                    liveResize="true" rowsPerPageTemplate="10,20,30" 
                                    paginatorPosition="top">

                                    <p:column  selectionMode="multiple" width="16" disabledSelection="true"/>
                                    <p:column  headerText="Permiso" disabledSelection="true">
                                        <p:outputLabel value="Gestionar #{permissions.name}"/>
                                    </p:column> 
                                </p:dataTable>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" align="center">
                                <p:commandButton value="Aceptar" oncomplete="PF('dialogRolesView').hide()"
                                                 update="@this"/>
                            </td>
                        </tr>
                    </table>
                </h:form>
            </p:dialog>
<!--           finaliza el dialogo para visualizar un rol           -->
            
            <p:growl autoUpdate="true" showDetail="true" life="8000" />
            <h:form id="formRoles">
                <p:remoteCommand name="roleInit" update=":formRoles:scrolesDataTable" />
                <p:dataTable id="scrolesDataTable" draggableColumns="true" emptyMessage="" 
                         value="#{scrolesBean.rolesList}" var="roles"
                         paginator="true" rows="10"  
                         pageLinks="40"
                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} 
                         {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rowKey="#{roles.idRole}"
                         resizableColumns="true" selection="#{scrolesBean.scRolesSelected}"
                         liveResize="true" rowsPerPageTemplate="10,20,30" 
                         selectionMode="single" paginatorPosition="top"
                         sortBy="#{roles.name}">
                <f:facet name="header">
                    <p:commandButton icon="ui-icon-plus" id="btnAdd" style="float: right;"  
                    oncomplete="PF('dialogRolesSave').show()">
                        <p:tooltip for="btnAdd" value="Agregar un Grupo"/>
                    </p:commandButton>
                </f:facet>
                
                <p:column filterMatchMode="contains"  filterBy="#{roles.name}" id="columnRolName" headerText="Rol" sortBy="#{roles.name}">    
                    <center>
                        <p:outputLabel value="#{roles.name}" id="lblRolname"/>
                        <p:tooltip for="lblRolname" value="#{roles.name}"/>
                    </center>
                </p:column>
                <p:column filterMatchMode="contains"  filterBy="#{roles.description}" id="columnRolDescription" headerText="Descripción" sortBy="#{roles.description}">    
                    <center>
                        <p:outputLabel value="#{roles.description}" id="lblRoleDescription"/>
                        <p:tooltip for="lblRoleDescription" value="#{roles.description}"/>
                    </center>
                </p:column>
                    <p:column filterMatchMode="contains"  filterBy="#{scrolesBean.getFormatDate(roles.creationDate)}" id="columnRolCreationDate" headerText="Fecha de Creación" 
                              sortBy="#{scrolesBean.getFormatDate(roles.creationDate)}">    
                    <center>
                        <p:outputLabel value="#{scrolesBean.getFormatDate(roles.creationDate)}" id="lblRoleCreationDate"/>
                        <p:tooltip for="lblRoleCreationDate" value="#{scrolesBean.getFormatDate(roles.creationDate)}"/>
                    </center>
                </p:column>
                <p:column headerText="Admin" width="100">
                    <center>
                        <p:commandButton icon="ui-icon-search" id="btnSearch" update=":formUpdateScRole"
                            actionListener="#{scrolesBean.getModulePermissionsByRoleSelectedView()}"
                            oncomplete="PF('dialogRolesView').show()">
                                <p:tooltip for="btnSearch" value="Visualizar un Rol o Grupo"/>
                            </p:commandButton>
                            <p:spacer width="3"/>
                        <p:commandButton icon="ui-icon-pencil" id="btnEdit" 
                        actionListener="#{scrolesBean.getModulePermissionsByRoleSelected(roles)}"
                        oncomplete="PF('dialogRolesUpdate').show()" update=":formUpdateScRole">
                            <p:tooltip for="btnEdit" value="Editar Grupo"/>
                        </p:commandButton>
                        <p:spacer width="3"/>
                        <p:commandButton icon="ui-icon-close" id="btnDelete" 
                        actionListener="#{scrolesBean.getModulePermissionsByRoleSelected(roles)}" 
                        update=":formDeleteScRole" oncomplete="PF('dialogRolesDelete').show()">
                            <p:tooltip for="btnDelete" value="Eliminar Grupo"/>
                        </p:commandButton>
                    </center>
                </p:column>    
            </p:dataTable>
            </h:form>
        </div>
        
    </h:body>
</html>

